/// 自定义迭代器
// 定义结构体
struct Counter {
    count: u32,
}
// 实现这个迭代器的的方法
impl Counter {
    fn new() -> Counter {
        Counter {
            count: 0,
        }
    }
}

// 实现迭代器Iterator的特征
impl Iterator for Counter {
    type Item = u32;
    fn next(&mut self) -> Option<Self::Item> {
        self.count += 1;
        if self.count < 6 {
            Some(self.count)
        } else {
            None
        }
    }
}
fn main() {
    let mut counter = Counter::new();
    for i in (0..9) {
        if let Some(v) = counter.next(){
            println!("i = {}, v = {}", i, v);
        } else {
            println!("i = {}, at end", i);
        }
    }
    println!("Hello, world!");
}
